<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/page/inc/taglib.jsp" %>
<!-- 引用ztree 的css -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/ztree/css/zTreeStyle/zTreeStyle.css"
      type="text/css">
<div class="pageContent">
    <form method="post" id="form" action="${pageContext.request.contextPath}/system/role/updatePermission"
          class="pageForm required-validate">
        <div class="pageFormContent" layoutH="56">
            <!-- 关闭窗口 -->
            <input type="hidden" name="callbackType" value="closeCurrent"/>
            <!-- 隐藏表单 -->
            <!-- 授权到那个角色的id -->
            <input type="hidden" name="id" value="${requestScope.id}"/>

            <ul id="tpPermissionTree" class="ztree"></ul>

        </div>
        <div class="formBar">
            <ul>
                <!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit">保存</button>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="button">
                        <div class="buttonContent">
                            <button type="button" class="close">取消</button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/statics/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/statics/ztree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript">
    var setting = {
        data: {
            simpleData: {
                enable: true
            }
        }, check: {
            enable: true,
            chkboxType: {
                "Y": "ps",
                "N": "s"
            }
        }
    };

    var zNodes = ${requestScope.ztreeBeans};

    $(document).ready(function () {
        //ztree初始化  ztree 设置参数   ztree 内容
        $.fn.zTree.init($("#tpPermissionTree", $.pdialog.getCurrent()), setting, zNodes);
    });

    //监听form表单提交事件并且重写
    $("#form", $.pdialog.getCurrent()).submit(function () {
        //获取ztree 的js对象
        var treeObj = $.fn.zTree.getZTreeObj("tpPermissionTree", $.pdialog.getCurrent());
        //拿到ztree选中的节点
        var nodes = treeObj.getCheckedNodes(true);

        for (var i = 0; i < nodes.length; i++) {
            var node = nodes[i];
            //动态拼接到form表单里面
            $("#form", $.pdialog.getCurrent()).append("<input type='hidden' name='pid' value='" + node.id + "' />");
        }
        return validateCallback(this, dialogAjaxDone);
        //return false;
    })
</script>
